﻿namespace AlgorithmInterview.Chapter04._01;

// 找出数组中唯一的重复元素
public class Test03
{
    /// <summary>
    /// 异或法
    /// </summary>
    /// <param name="array"></param>
    /// <returns></returns>
    public int FindDup(int[] array)
    {
        if (array == null)
            return -1;
        int len = array.Length;
        int result = 0;
        int i;
        for (i = 0; i < len; i++)
        {
            result ^= array[i];
        }

        for (i = 1; i < len; i++)
        {
            result ^= i;
        }

        return result;
    }
}